package com.miyake.loveviewweb.client.community;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.miyake.loveviewweb.client.community.FriendListWidget.FriendListType;
import com.miyake.loveviewweb.client.dialog.DialogHandler;
import com.miyake.loveviewweb.client.dialog.IDialogPanel;
import com.miyake.loveviewweb.client.service.DataService;
import com.miyake.loveviewweb.shared.model.UserModel;

public class FriendSearchPanel extends Composite implements IDialogPanel {

    private DialogHandler handler;

    public FriendSearchPanel() {
        VerticalPanel panel = new VerticalPanel();
        panel.setWidth("600px");
        panel.setHeight("400px");
        initWidget(panel);
        FriendListWidget friendList = new FriendListWidget(FriendListType.AllUsers) {

            @Override
            protected void onSelect(UserModel element) {
                DataService.Util.getInstance().addFriend(element.getKey(), new AsyncCallback<Void>() {

                    public void onFailure(Throwable caught) {
                        // TODO Auto-generated method stub
                        
                    }

                    public void onSuccess(Void result) {
                        handler.onOK();
                    }
                    
                });
                
            }
            
        };
        panel.add(friendList);
        friendList.update();
    }
    
    public void setDialogHandler(DialogHandler handler) {
        this.handler = handler;
    }

    public Composite getComposite() {
        return this;
    }

}
